[asp新手]关于字符串之间空格的问题 [急........

来源:百度知道 编辑:UC知道 时间:2024/06/07 13:55:49
直说了。。

我想将一个字符串中的空格平均分配,也就是说如果有多个空格我就像保留一个。
例如: dim str
str="a b bcd d e ff"

我想使 str字符串中的多个空格变成一个空格.例如:

我想得到这样的结果:"a b bcd d e ff"

写了个函数给你:
<%
str="fadf dhfj     thg"
response.write oneblank(str) '调用函数

function oneblank(s)
dim isblank,i,newstr
isblank=false
for i=1 to len(s)
a=mid(s,i,1)
if isblank=true then '前一字符为空格
if a<>" " then
newstr=newstr&a
isblank=false
end if
else '前一字符非空格
newstr=newstr&a
if a=" " then isblank=true
end if
next
oneblank=newstr
end function
%>

str=replace("a b bcd d e ff"," "," ")

楼上的方法可行,不过最简单的方法如下:

function oneblank(c)
while Instr(c,"--")=0
c=replace(c,"--","-")
wend
end function

把“-”改成空格。